package com.company.OfferGuide;

import com.company.ListNode;

import java.util.Stack;

public class 从尾到头打印链表 {

    public int[] reversePrint(ListNode head) {
        if (head == null) return new int[]{};
        Stack<ListNode> stack = new Stack<>();
        while (head != null) {
            stack.push(head);
            head = head.next;
        }
        int[] data = new int[stack.size()];
        int i = 0;
        while (!stack.isEmpty()) {
            data[i++] = stack.pop().val;
        }
        return data;
    }

}
